package com.moxiao.yfjh.module.system.sms.utils;

import com.moxiao.yfjh.module.system.sms.client.SmsRemoteApi;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * @version 1.0
 * @Author zhk
 * @Date 2023/11/10 15:28
 **/
@Component
public class AlyISmsUtils {
    @Resource
    private SmsRemoteApi smsRemoteApi;

    public static final String PHONE_RULES = "^(\\+|00){0,2}(9[976]\\d|8[987530]\\d|6[987]\\d|5[90]\\d|42\\d|3[875]\\d|2[98654321]\\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)\\d{1,14}$";

    /**
     * 校验手机号
     *
     * @param phoneNum
     * @return
     */
    public static boolean checkPhoneNum(String phoneNum) {
        return !StringUtils.isEmpty(phoneNum) && phoneNum.matches(PHONE_RULES) && checkMobileNum(phoneNum);
    }

    /**
     * 校验手机号
     *
     * @param mobileNum
     * @return
     */
    public static boolean checkMobileNum(String mobileNum) {
        if (mobileNum.startsWith("1") && mobileNum.length() == 11) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 发送短信
     *
     * @param mobile
     * @param text
     * @return
     * 具体申请请查看文档 https://blog.csdn.net/m0_70810591/article/details/131855929
     */
    public JSONObject sendSms(String mobile, String text){
        return JSONObject.parseObject(smsRemoteApi.sendSms(mobile, text));
    }


}
